package com.example.mqtt.common.response;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/3/29 22:58
 **/
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Response<?> handleException(Exception e) {
        // 已经被AOP处理的异常不会进入这里
        log.warn(e.getMessage());
        if (e.getMessage().isEmpty()){
            return Response.error(500, "系统繁忙，请稍后再试");
        }
        return Response.error(500, e.getMessage());
    }
}
